﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Globalization;

namespace tjb.WebTest.HttpContextTest
{
    public partial class WebForm1 : System.Web.UI.Page
    {
        private const string key = "___httpcontextitems";
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {

            }
        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            Button2_Click(null, null);
            string m = "不存在！！";
            if (HttpContext.Current.Items.Contains(key))
                m = "<br> Items:" + HttpContext.Current.Items[key].ToString();

            m += "<br> Session:" + HttpContext.Current.Session[key] as string;

            Response.Write(m);
        }

        protected void Button2_Click(object sender, EventArgs e)
        {
            DateTimeFormatInfo format = new DateTimeFormatInfo();
            format.DateSeparator = "-";
            format.FirstDayOfWeek = DayOfWeek.Monday;
            
            HttpContext.Current.Items[key] = DateTime.Now.ToString(format);
            HttpContext.Current.Session[key] = DateTime.Now.ToString("yyyyOMModd HH:mm:ss,fff");

        }
    }
}
